package controller;

import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import pojo.Customer;
import pojo.Page;
import pojo.Vender;
import response.Result;
import service.CustomerService;

import javax.annotation.Resource;
import java.util.List;

/**
 * @ClassName 刘星宇
 * @Description TODO
 * @date 2022/12/2 11:34
 * @Version 1.0
 */
@RestController
public class CustomerController {
    @Resource
    private CustomerService customerService;
    @RequestMapping("getCustomer")
    public Result getCustomer(Integer currentPage, Integer pageSize, String customerCode, String name){
        Page<Customer> page = new Page<Customer>();
        page.setCurrentPage(currentPage);
        page.setPageSize(pageSize);
        Customer customer = new Customer();
        customer.setCustomerCode(customerCode); ;
        customer.setName(name);
        int totalRecord = customerService.getCount1(page, customer);
        List<Customer> list = customerService.customerAllByPage(page,customer);
        page.setLists(list);
        page.setTotalRecord(totalRecord);
        return Result.ok(page);
    }
    //新增
    @RequestMapping("customerAdd")
    public int customerAdd(@RequestBody Customer customer){
        int i = customerService.AddCustomer(customer);
        return i;
    }
    //修改
    @RequestMapping("customerUpd")
    public int venderUpd(@RequestBody Customer customer){
        int i = customerService.UpdateCustomer(customer);
        return i;
    }
    //删除
    @RequestMapping("customerDel")
    public int venderDel(String customerCode){
        int i = customerService.DelCustomer(customerCode);
        return i;
    }
}
